package lockTest;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author : yang.xp
 * @date : 2022/9/20 20:43
 * @description :
 */
public class DirectMemoryOOM {

    // -Xms10m -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m -XX:+PrintGCDetails

    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) throws Exception {
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];
        unsafeField.setAccessible(true);
        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        int num = 0;
        while (true) {
            System.out.println(num++);
            unsafe.allocateMemory(_1MB);
        }
    }
}